import { Button, Toast } from 'antd-mobile';
import { Input } from 'antd';
import React,{useEffect, useState} from 'react';
import { history } from 'umi'
import { eduFeedback,getQuestionDetailById } from '@/services/edu'
const { TextArea } = Input;
import style from './index.less'

function Question() {
  const { query = {} } = history.location as any;
  const { id } = query;
  const [content,setcontent] =useState('')
  const [question,setQuestion] =useState<any>({})
  const fetchquestionDetail = async()=>{
    const res = await getQuestionDetailById({questionId:id})
    if(res.code===1){
      setQuestion(res.response)
    }
  }
  useEffect(()=>{
    if(id){
      fetchquestionDetail()
    }
    
  },[])
  const handleContent =(v)=>{
    setcontent(v.target.value)
  }
  const handleeduFeedback =async()=>{
    if(!content) return Toast.fail('请填写报错信息')
    const res = await eduFeedback({
      title:'222222',
      remark:content,
      id,
    })
    if(res?.code===1){
      setcontent('')
      Toast.success('提交成功',1.5,()=>{
        history.goBack()
      })
    }

  }
  return (
    <div className={style.question}>
      <div className={style.title}>{question.shortTitle||'题干'}</div>
      <div className={style.textArea}>
        <TextArea onChange={handleContent} rows={4}></TextArea>
      </div>
      <Button type="primary" onClick={handleeduFeedback}>提交</Button>
    </div>
  );
}

export default Question;
